﻿using UnityEngine;
using System.Collections;
using System.Text;

namespace Mga
{
	public class LocalSaveData
	{
		private LocalSaveData() { }
		public static readonly LocalSaveData Instance = new LocalSaveData();
		StringBuilder sb = new StringBuilder();
		public void Save(string key, string value)
		{
			PlayerPrefs.SetString(GetIOKey(key), value);
		}

		public void Clear(string key)
		{
			PlayerPrefs.DeleteKey(GetIOKey(key));
		}
		public string GetValue(string key)
		{
			return PlayerPrefs.GetString(GetIOKey(key));
		}
		private string GetIOKey(string key)
		{
			sb.Remove(0, sb.Length);
			sb.Append(NetWriter.GetUrl());
			sb.Append(GameSetting.Instance.DeviceID);
			sb.Append(key);
			string keys = MD5Utils.Encrypt(System.Text.Encoding.UTF8.GetBytes(sb.ToString()));
			Debug.Log(keys);
			return keys;
		}
	}
}
